package mailprj;

// File Name SendHTMLEmail.java

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendHTMLEmail
{
   public static void main(String [] args)
   {
      
      // Recipient's email ID needs to be mentioned.
      String to = "t.mitrareddy@gmail.com";

      // Sender's email ID needs to be mentioned
      String from = "t.mitrareddy@gmail.com";

      // Assuming you are sending email from localhost
      String host = "smtp.gmail.com";

       Properties props = new Properties();
       props.put("mail.smtp.starttls.enable", "true");
       props.setProperty("mail.user", "myuser");
       props.setProperty("mail.password", "mypwd");
       props.put("mail.smtp.host", "smtp.gmail.com");
       props.put("mail.smtp.socketFactory.port", "465");
       props.put("mail.smtp.socketFactory.class",
                 "javax.net.ssl.SSLSocketFactory");
       props.put("mail.smtp.auth", "true");
       props.put("mail.smtp.port", "25");
       props.put("mail.smtp.debug", "true");
      // Get the default Session object.
      Session session =
          Session.getDefaultInstance(props, new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication("t.mitrareddy@gmail.com", "minnu.mouni3001");
              }
          });

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Send the actual HTML message, as big as you like
         message.setContent("<h1>This is actual message</h1>",
                            "text/html" );

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}